<html xmlns="http://www.w3.org/1999/xhtml" >
<%@ page language="java" import	="java.io.*,java.sql.*" %>

<%@include file="../dbcon.jsp"%>
<%
	int iMsgId = 1; 
	int iSno = 0;
	int iRecType = 0;
	
String sTitle = "",sBusinessid = "",sBustypeid = "", sVat = "", sInlandrevenueno="";
	String sLocation = "", sMobile = "", sEmail = "", sLandline = "", sDesc = "", sAddress="";
	int iLandType = 0;
			
	String sTmp = request.getParameter("hid_RecType");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iRecType = Integer.parseInt(sTmp);
	
	sTmp = request.getParameter("hid_RecSno");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iSno = Integer.parseInt(sTmp);
//System.out.println("iSno : "+ iSno);			
	if ( sTmp == null || sTmp.equals("null") || sTmp.equals("") )
	{
		response.sendRedirect("frm_usedcar.jsp");
		//System.out.println("sTmp : "+ sTmp);				
		return;
	}
	
	
	sTitle = request.getParameter("txt_title");
	sBusinessid = request.getParameter("ddl_businessid");	
	sBustypeid = request.getParameter("ddl_bustypeid");	
	sVat = request.getParameter("txt_vat");
	sInlandrevenueno = request.getParameter("txt_inlandrevno");
	sLocation = request.getParameter("txt_location");
	sMobile = request.getParameter("txt_mobile");
	sAddress = request.getParameter("txt_address");	
	sEmail = request.getParameter("txt_email");
	sLandline = request.getParameter("txt_landline");
	sDesc = request.getParameter("txt_desc");
	
	
			
	
	try{		
		String sRtnMsg = "";
		if ( iRecType == 1 )
		{
			String sQry = "insert into tbl_business(business_id,busstype_id,vat,";
			sQry += "inland_revenue, location,";
			sQry += "mobile ,landline ,email ,address ,title ) values(";
			sQry +=  sBusinessid +"','"+ sBustypeid +"',";
			sQry += "'"+ sVat +"','"+ sInlandrevenueno +"',"+ sLocation ;
			sQry += ",'"+ sMobile +"','" + sLandline +"','"+ sEmail +"','"+ sAddress +"','"+ sTitle +"'";
			sQry += ")";
			
		System.out.println("tbl_business Qry : "+ sQry);					

			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();

			iMsgId = 1;
			System.out.println("Insert Successfully");
		}
		else if ( iRecType == 2)
		{
			String sQry = "update tbl_business set ";
			sQry += "business_id='"+ sBusinessid +"',";
			sQry += "busstype_id='"+ sBustypeid +"',";
			sQry += "vat='"+ sVat +"',";			
			sQry += "inland_revenue='"+ sInlandrevenueno +"',";			
			sQry += "location='"+ sLocation +"',";
			sQry += "mobile='"+ sMobile +"',";
			sQry += "landline='"+ sLandline +"',";
			sQry += "email='"+ sEmail +"',";
			sQry += "address='"+ sAddress +"',";
			sQry += "title='"+ sTitle +"',";
			sQry += " where id="+ iSno;
		System.out.println("tbl_business Qry : "+ sQry);					
		
			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();
					
			iMsgId = 3;
			System.out.println("Update Successfully");
		}
	}
	catch(Exception e)
	{	
		System.out.println("Failed : "+ e);	
		if ( iRecType == 1 ) iMsgId = 2;
		else iMsgId = 4;
	}
	
	if ( Con != null ) Con.close();
	response.sendRedirect("../frm_msg.jsp?MsgID="+ iMsgId);
	//System.out.println("Insert Failed");
%>
</html>